package bgu.gaoxu.diary.utils;

import android.content.Context;
import android.content.SharedPreferences;

import bgu.gaoxu.diary.entity.UserIF;

/**
 * Created by GA666666 on 2020/11/15 1:56
 */

public class LoginState {
    private static final int MODE_PRIVATE = 0;
    private SharedPreferences mySharedPreferences,sharedPreferences;
    public int verify(Context context){
        mySharedPreferences = context.getSharedPreferences("user_info", MODE_PRIVATE);
        if (mySharedPreferences.getInt("user_id", -1)!=-1){
            return mySharedPreferences.getInt("user_id", -1);
        }else{
            return -1;
        }
    }
    public UserIF getUserInfo(Context context){
        UserIF u = new UserIF();
        mySharedPreferences = context.getSharedPreferences("user_info", MODE_PRIVATE);
        if (mySharedPreferences.getInt("user_id", -1)!=-1){
            u.setDiarynum(mySharedPreferences.getInt("diary_num", 0));
            u.setErro_code(0);
            u.setFriendnum(0);
            u.setNickname(mySharedPreferences.getString("user_nickname",""));
            u.setUser_id(mySharedPreferences.getInt("user_id", -1));
            u.setUser_name(mySharedPreferences.getString("user_name",""));
            u.setUser_psd(mySharedPreferences.getString("user_psd",""));
            u.setUser_photo(mySharedPreferences.getString("user_photo",""));
            return u;
        }else{
            return u;
        }
    }
}
